no strict 'refs';

foreach my $action (qw(
    dir_check dir_install
    file_install text_install file_append file_modify file_comment file_uncomment
    x509_cert x509_install
))
{
    &{$action}(ref eq 'ARRAY' ? @$_ : $_)
	foreach fetchall_array($action);
}

if (my $touch = fetchall_hash('touch'))
{
    open my $fh, ">>$_"
	foreach sort keys %{ $touch };
}

if (my $chmod = fetchall_hash('chmod'))
{
    set_attr $_, { mode=>$chmod->{$_} }
	foreach sort keys %{ $chmod };
}

if (my $chown = fetchall_hash('chown'))
{
    while (my ($path, $param) = each %{ $chown })
    {
	my ($uid, $gid) = ref $param eq 'ARRAY' ? @{ $param } : split /:/, $param;

	set_attr $path, { uid=>$uid, gid=>$gid };
    }
}

foreach my $cmd (fetchall_array('run'))
{
    if (ref $cmd eq 'CODE')
    {
	$cmd->(\%m, $hostname);
    }
    else
    {
	command(ref eq 'ARRAY' ? @$cmd : $cmd);
    }
}

1;
